package com.yj.forum.controller;

import com.yj.forum.common.AppResult;
import com.yj.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

//返回结果是数据
@RestController
//一级路径
@RequestMapping("/test")
@Api(tags = "测试类相关接口")
public class TestController {
    @ApiOperation("测试spring启动接口")
    @GetMapping("/hello")
    public String hello() {
        return "hello Spring boot";
    }

    @ApiOperation("测试异常")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception异常");
    }

    @ApiOperation("测试自定义异常")
    @GetMapping ("/appException")
    public AppResult testApplicationException() throws Exception {
        throw new ApplicationException("这是一个ApplicatioException异常");
    }

    @ApiOperation("测试返回 你好+传⼊参数")
    @PostMapping("/helloName")
    public AppResult<String> helloName(@ApiParam(value = "名字", required = true) @RequestParam(value = "name") String  name) {
        return  AppResult.success("hello: " + name);
    }
}
